//
//  SelectChildViewController.m
//  AndCampus
//
//  Created by 史宵宵 on 2018/1/8.
//  Copyright © 2018年 史宵宵. All rights reserved.
//

#import "SelectChildViewController.h"
#import "MegaphoneViewController.h"
#import "ResultListViewController.h"

@interface SelectChildViewController ()

@end

@implementation SelectChildViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    if (self.selectChildOrParentType == KSelectMegaphoneType) {
        self.title = @"传声筒";
        UIImage *image = [UIImage imageNamed:@"megaphone_bg"];
        self.view.layer.contents = (id) image.CGImage;
    }else{
        self.title = @"家长寄语";
        UIImage *image = [UIImage imageNamed:@"AdviceToParents_bg"];
        self.view.layer.contents = (id) image.CGImage;
    }
    [self creatView];
}

- (void)creatView{
    UILabel *textLabel = [[UILabel alloc]init];
    textLabel.frame = CGRectMake(30, 30, kScreenW - 60, 40);
    textLabel.backgroundColor = RGBColor(23 ,30 , 41);
    textLabel.text = @"开启和孩子的互动时间吧！";
    textLabel.clipsToBounds = YES;
    textLabel.layer.cornerRadius = 15;
    textLabel.layer.borderColor = rgba(39, 51, 70, 0.2).CGColor;
    textLabel.layer.borderWidth = 2;
    textLabel.textColor = [UIColor whiteColor];
    textLabel.textAlignment = NSTextAlignmentCenter;
    textLabel.font = [UIFont systemFontOfSize:15];
    [self.view addSubview:textLabel];

    for (int i = 0; i < self.childArray.count; i ++) {
        ChildInfo *childInfo = self.childArray[i];
        
        UIImageView *iconImage = [[UIImageView alloc]init];
        iconImage.frame = CGRectMake((kScreenW - 60)/2,CGRectGetMaxY(textLabel.frame)+(80 + 30)*i+ 20,60,60);
        [iconImage sd_setImageWithURL:[NSURL URLWithString:childInfo.icon] placeholderImage:KDEFAULTHEAD];
        iconImage.clipsToBounds = YES;
        iconImage.layer.cornerRadius = 30;
        iconImage.layer.borderColor = rgba(255, 255, 255, 0.5).CGColor;
        iconImage.userInteractionEnabled = YES;
        iconImage.tag = 1000 + i;
        [iconImage addGestureRecognizer:[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(isSelectChild:)]];
        [self.view addSubview:iconImage];
        
        UILabel *nameLabel = [[UILabel alloc]init];
        nameLabel.frame = CGRectMake((kScreenW - 100)/2,CGRectGetMaxY(iconImage.frame)+10,100,20);
        nameLabel.text = childInfo.name;
        nameLabel.textAlignment = NSTextAlignmentCenter;
        nameLabel.textColor = [UIColor whiteColor];
        [self.view addSubview:nameLabel];
    }
}
- (void)isSelectChild:(UIGestureRecognizer *)tap{
    MyLog(@"%ld",tap.view.tag);
    ChildInfo *childInfo = self.childArray[tap.view.tag - 1000];
    if (self.selectChildOrParentType == KSelectMegaphoneType) {
        MegaphoneViewController *megaphoneVC = [[MegaphoneViewController alloc]init];
        megaphoneVC.childId = childInfo.user_id;
        [self.navigationController pushViewController:megaphoneVC animated:YES];
    }else{
        ResultListViewController *reaultListVC = [[ResultListViewController alloc]init];
        reaultListVC.monthListType = KPersentMonthListType;
        reaultListVC.childId = childInfo.user_id;
        [self.navigationController pushViewController:reaultListVC animated:YES];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
